Skip to content

fix(server): conversation summaries keep up so handoffs can use them - #132

Merged
ScriptedAlchemy merged 37 commits into
mainfrom
t3/fix-summary-handoff-throughput
Nov 16, 2026
Merged

ScriptedAlchemy merged 37 commits into
mainfrom
t3/fix-summary-handoff-throughput

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Why

Conversation summaries exist so handoffs can replace old history with something compact, but they rarely did. Of 1,005 history items left out of handoffs, only 82 (8%) were replaced by summaries. One handoff used 0 summaries while 213 of its omitted items already had leaf summaries. An audit of live data traced this to three causes:

  • Passes piled up. Each completed run queued its own chain of summary passes. There were 48 pending across 16 threads, and one waited 51 minutes.
  • Roll-ups starved. A pass made every pending leaf before any roll-up, so busy threads ended up with hundreds of 2.6 KB leaves and almost no roll-ups.
  • One bad chunk blocked a thread. A chunk that kept returning empty output failed every pass at the same spot.

What changed

  • One pending pass per thread. That's safe because a pass reads the whole thread when it runs. A pass that a newer pending pass supersedes is cancelled, so it gets pruned. A later run's pass collapses only into a fresh pending row, never into one that is retrying. Process-loss reconcile counts the passes it cancels this way in cancelled.
  • Roll-ups before new leaves. Within the same cap of 3, a pass first rolls up runs of four current roots, then makes leaves. A skipped stretch doesn't block roll-ups, and its items are still replayed in full by delivery.
  • A bad stretch is skipped; an outage skips nothing.
    • A failure counts against a stretch only when that stretch fails in a pass where another generation succeeded.
    • TextGenerationError gains an optional kind ("empty" | "invalid-output" | "output-limit") for an unusable reply. The provider adapters that summaries use set empty and invalid-output. output-limit comes only from custom text generators, and summaries never use those.
    • A pass where nothing succeeds counts nothing. It marks its failures as suspects, which go behind other work. While nothing has succeeded it tries one suspect, the one that has waited longest, so a stretch that keeps failing can't hold every pass.
    • An unlabelled failure, such as a timeout or an HTTP 400 for a content filter or an oversized prompt, fails the pass so it retries, but only when nothing was generated in that pass. Its chunk becomes an uncounted suspect, so the next pass works around it. After a success, the pass records the reason and finishes normally, and the failure counts toward a skip only when another summary succeeds after it in that pass. A provider that answers once and then times out or rate-limits therefore skips nothing.
    • Two counted failures skip a stretch. Skips are keyed by the summary model, so changing the model retries them. Turning summaries off and back on for the project clears them, even while a pass is running.
    • The failure ledger lives server-side, capped at 64 entries, of which at most 48 can be skips. Trimming drops suspects with no counted failure first.
  • Skips are visible. Skipped sources no longer count as waiting for a summary. Every pass that has skips, including one that wrote summaries, shows the skip reason. Web and mobile both use the shared conversationSummaryPassLabel.
  • Claude's out-of-retries failure (error_max_structured_output_retries, exit 1) is labelled unreadable, so it can't stall a thread.

Scope

  • Covers pass scheduling, ordering and failure handling.
  • Leaves out the shared maintenance worker, the summary prompt text, and a separate action to reset skips. Re-enabling summaries is the reset.

Tradeoffs

  • Counting only failures beside a success. An outage never causes a skip, including one where the first request of a pass still succeeds. The price is that a thread whose only remaining work is one bad stretch stays one failure short of a skip until new messages bring new work. That costs one call per pass in the meantime.
  • An outage costs one call per pass only while the thread's failing work fits in the ledger. Once suspects overflow the 64 entries, the trimmed ones come back as fresh work, so a long outage on a thread with many stretches keeps trying up to 3 a pass. Counted failures are trimmed last, so an outage doesn't erase them.
  • An unlabelled failure before any success fails the pass. That keeps an outage to one call per pass, but a chunk that is always rejected or always times out costs more passes to skip when it is first in line: the pass that tries it first fails, and the next pass works around it and counts it. A chunk at the front of the thread takes four passes to skip (two fail and the worker retries them), not two. Roll-ups stop at it as a gap until it is skipped.
  • A bad chunk at the open end keeps changing its key. The newest chunk grows as messages settle, and each change gives it a new key, so its failures start over. It can be skipped only once it stops growing.
  • More than 48 permanently bad stretches in one thread keep cycling. The oldest skips leave the ledger and are retried. That's rare, and better than new failures never being recorded.

Blast Radius

  • Outbox. For one effect type, conversation-summary.generate.
  • The summary pass, plus a settings subscriber in the summaries service that clears a project's failure ledger when summaries are turned back on.
  • The TextGenerationError contract. It gains an optional kind. The Claude, Codex and managed-Codex driver wrappers now pass that error through unchanged; message and tag are the same.
  • The pass label in packages/client-runtime, shared by web and mobile.

Verification

  • Every fix landed with a failing test first, across six review rounds. The rounds covered outages, livelock from correlated failures, a ledger full of skips, Claude exit codes, charging only real failures, unlabelled errors, re-enabling (including a pass that is running when summaries are turned back on), an outage that overflows the ledger, and a partial outage.
  • The summary and effect-worker test files pass 76 tests.
  • vp run check:changed passes format, lint, knip, graphql, and 304 tests in 17 files. Its typecheck flagged a readonly tuple in a test, which I fixed and rechecked.

🤖 Generated with Claude Code

ScriptedAlchemy and others added 7 commits November 16, 2026 02:12
Each completed run inserts its own conversation-summary pass, so pending
passes pile up and a context restart stays refused. The outbox still
accepts a second run while the first is pending.

Co-authored-by: Cursor <cursoragent@cursor.com>
A second run no longer starts its own chain while a pass is already
pending. A retry or process restart leaves the queued successor and
does not resume the pass it already replaced.

Co-authored-by: Cursor <cursoragent@cursor.com>
A pass with eight current leaves and an uncovered tail still summarizes
the tail first, so busy threads never build the roll-ups a handoff can
fit. A gap in the middle must still be replaced before roots on either
side are rolled together.

Co-authored-by: Cursor <cursoragent@cursor.com>
A pass spent its whole cap on new leaves, so a busy thread never built
roll-ups a handoff can fit. Runs of four current roots that end before
the first uncovered gap now roll up first. Roots across that gap still
wait for the replacement leaf.

Co-authored-by: Cursor <cursoragent@cursor.com>
Empty or invalid output from the oldest chunk fails the whole pass, so
the next pass retries that chunk and later stretches stay uncovered.
A timeout should still fail the pass.

Co-authored-by: Cursor <cursoragent@cursor.com>
A deterministic failure of the oldest chunk failed the whole pass, so
later stretches never ran. The pass records that failure and continues.
After the second one it leaves the chunk uncovered instead of retrying
it. Timeouts still fail the pass.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a67d769

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

ScriptedAlchemy and others added 22 commits November 16, 2026 03:02
…ng pass does not absorb a later run's

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… pass absorbs a later run's

A pass that stepped aside for a pending successor landed as failed, which pruning never deletes, while the restart path marked the same case succeeded. Both now cancel with one reason. A later run's pass collapsed into any pending pass, including one already retrying, so exhausting that retry dropped the later run's summaries. It now collapses only into a pass that has not started.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…aries act on

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…not its wording

Summaries decided whether a failed chunk could be skipped by matching error messages, which missed the custom text generators' "returned no text." and "couldn't read" replies. TextGenerationError now carries kind: empty or invalid-output, set where each adapter produces such a reply, and passed through the Claude and Codex driver wrappers that used to drop it. Outages, timeouts, sign-in, cancellation and unsupported providers stay unclassified.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eed, expires with the model, and does not block roll-ups

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…del, and roll-ups pass a skipped stretch

A chunk counted a failure even when every call failed, so an outage or a model without structured output skipped a thread's whole history for good. A failure now counts only when another summary in the same pass succeeded; a pass with no success records the failure and stops its chain. Skip keys digest the summary model with the chunk, so changing the model gives the stretch a new chance.

A skipped stretch never gets a leaf, yet it was the first gap, so nothing after it could roll up. It no longer splits the forest; its items stay uncovered, so delivery still replays them.

The failure ledger left the client contract. It is stored beside the pass on the server, hashed and capped, and is read before the deleted, archived and summaries-off paths so they no longer wipe it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…'s progress

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d keeps progressing

A pass whose three attempts all failed recorded nothing, as protection against a model outage. When three correlated pieces of work failed, such as every roll-up window holding one bad child or three bad leaf stretches at the front, each later pass retried them first and the thread never progressed. Such a pass now marks its failures as suspects without counting them. Later passes try suspects after other work, and the first pass that succeeds elsewhere counts them toward the skip. An outage still counts nothing and costs at most three calls per pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The ledger keeps its last 64 entries in insertion order. A skipped stretch is never tried again, so it is never re-inserted and drifts to the front, where the cap dropped it first. A long outage that marks many stretches as suspects could then evict a skip and retry known-bad work. Trimming now drops other failures before skips.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An exit-0 run whose final result had no readable structured output was always labelled invalid-output. That included error_during_execution and API error results, so summaries blamed the stretch for a failed run. The label now follows the result: a success result with an unreadable payload, or running out of structured output retries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ies is labelled unreadable

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es is labelled unreadable

The CLI exits 1 when the model never produced valid structured output, so the
label set on the exit-0 path never reached it. Summaries then failed the whole
pass on that chunk instead of counting it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…its own failures beside a success

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…side a success

The first pass to succeed after an outage charged every suspect at once, even
those it never retried, and a retried suspect that failed got charged twice.
A slightly flaky model then skipped healthy history. Now only a retried stretch
that fails in a pass where another summary succeeded is charged, once. Once a
pass has a success, suspects are tried in order like other work; until then
they still go last.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…del call while nothing succeeds

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…as succeeded

A thread with only suspect stretches spent three model calls a pass on a model
that may be down. Until a summary succeeds, a pass now tries one suspect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… skipped stretches fill the ledger

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er for new failures

Trimming kept every skip first, so with 64 or more skips a new failure was
dropped before it was saved. It never reached a skip and blocked roll-ups for
good. Trimming now keeps at most the 48 newest skips.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ScriptedAlchemy and others added 8 commits November 16, 2026 04:37
… with later failures

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…on re-enable, or reported

- A chunk that always times out must not hold every pass, and a bad oldest suspect must not
  hold every pass after an outage.
- Skipped sources no longer wait, and re-enabling summaries retries them.
- A stretch that failed once keeps its count when an outage overflows the ledger.
- An output-limit reply carries a kind, and process-loss reconcile reports the summary passes it
  cancels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ible label

- An unlabelled failure such as a timeout or an HTTP 400 still fails the pass, but its chunk
  becomes an uncounted suspect, so the next pass works around it. Earlier failures in that pass
  are recorded instead of dropped.
- Output-limit replies are labelled, so they count toward a skip.
- While nothing has succeeded, the suspect that waited longest is the one tried, so a stretch
  that keeps failing cannot stall a thread after an outage.
- Skipped sources leave the waiting count. A pass that wrote summaries shows its skip reason.
  Turning summaries back on for a project clears its failure ledger.
- Ledger trimming drops zero-count suspects before counted failures.
- Process-loss reconcile reports the summary passes it cancels. Roll-up keys use CONDENSE_FAN_IN.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…at a skip means, and how to undo it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-enable

A stretch that always fails without a label (a 400 or a timeout) is never skipped and fails
every pass after a success. A pass running while summaries are turned off and on writes the
cleared failure ledger back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ble reset survives a running pass

A failure that is not an unusable reply fails the pass only when nothing was generated in it;
beside a success it counts toward a skip like any other failure, and the pass finishes normally.
The pass writes its failure ledger in a transaction that keeps a reset made while it ran, so only
its own failures survive the reset.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ut skips nothing

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… summary succeeds

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@ScriptedAlchemy
ScriptedAlchemy merged commit 5846605 into main Nov 16, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant